using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using iBeauty.BusinessObjects;

namespace iBeauty.DAL
{
	public class SupplierDAO
	{
		public SupplierDAO()
		{
			DbProviderHelper.GetConnection();
		}
		public List<Supplier> GetSuppliers()
		{
			try
			{
				List<Supplier> lstSuppliers = new List<Supplier>();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [ID],[CreateDate],[ModifiedDate],[TimeStamp],[SupplierCode],[SupplierName],[Address],[Email],[Phone],[Fax],[PaymentType],[PaymentDate],[ATM],[AccountId],[Note] FROM [Supplier]",CommandType.Text);
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					Supplier oSupplier = new Supplier();
					oSupplier.ID = Convert.ToString(oDbDataReader["ID"]);

					if(oDbDataReader["CreateDate"] != DBNull.Value)
						oSupplier.CreateDate = Convert.ToDateTime(oDbDataReader["CreateDate"]);

					if(oDbDataReader["ModifiedDate"] != DBNull.Value)
						oSupplier.ModifiedDate = Convert.ToDateTime(oDbDataReader["ModifiedDate"]);

					if(oDbDataReader["TimeStamp"] != DBNull.Value)
						oSupplier.TimeStamp = Convert.ToDateTime(oDbDataReader["TimeStamp"]);

					if(oDbDataReader["SupplierCode"] != DBNull.Value)
						oSupplier.SupplierCode = Convert.ToString(oDbDataReader["SupplierCode"]);

					if(oDbDataReader["SupplierName"] != DBNull.Value)
						oSupplier.SupplierName = Convert.ToString(oDbDataReader["SupplierName"]);

					if(oDbDataReader["Address"] != DBNull.Value)
						oSupplier.Address = Convert.ToString(oDbDataReader["Address"]);

					if(oDbDataReader["Email"] != DBNull.Value)
						oSupplier.Email = Convert.ToString(oDbDataReader["Email"]);

					if(oDbDataReader["Phone"] != DBNull.Value)
						oSupplier.Phone = Convert.ToString(oDbDataReader["Phone"]);

					if(oDbDataReader["Fax"] != DBNull.Value)
						oSupplier.Fax = Convert.ToString(oDbDataReader["Fax"]);

					if(oDbDataReader["PaymentType"] != DBNull.Value)
						oSupplier.PaymentType = Convert.ToInt32(oDbDataReader["PaymentType"]);

					if(oDbDataReader["PaymentDate"] != DBNull.Value)
						oSupplier.PaymentDate = Convert.ToDateTime(oDbDataReader["PaymentDate"]);

					if(oDbDataReader["ATM"] != DBNull.Value)
						oSupplier.ATM = Convert.ToString(oDbDataReader["ATM"]);

					if(oDbDataReader["AccountId"] != DBNull.Value)
						oSupplier.AccountId = Convert.ToInt32(oDbDataReader["AccountId"]);

					if(oDbDataReader["Note"] != DBNull.Value)
						oSupplier.Note = Convert.ToString(oDbDataReader["Note"]);
					lstSuppliers.Add(oSupplier);
				}
				oDbDataReader.Close();
				return lstSuppliers;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public Supplier GetSupplier(string ID)
		{
			try
			{
				Supplier oSupplier = new Supplier();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [ID],[CreateDate],[ModifiedDate],[TimeStamp],[SupplierCode],[SupplierName],[Address],[Email],[Phone],[Fax],[PaymentType],[PaymentDate],[ATM],[AccountId],[Note] FROM [Supplier] WHERE [ID]=@ID",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,ID));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					oSupplier.ID = Convert.ToString(oDbDataReader["ID"]);

					if(oDbDataReader["CreateDate"] != DBNull.Value)
						oSupplier.CreateDate = Convert.ToDateTime(oDbDataReader["CreateDate"]);

					if(oDbDataReader["ModifiedDate"] != DBNull.Value)
						oSupplier.ModifiedDate = Convert.ToDateTime(oDbDataReader["ModifiedDate"]);

					if(oDbDataReader["TimeStamp"] != DBNull.Value)
						oSupplier.TimeStamp = Convert.ToDateTime(oDbDataReader["TimeStamp"]);

					if(oDbDataReader["SupplierCode"] != DBNull.Value)
						oSupplier.SupplierCode = Convert.ToString(oDbDataReader["SupplierCode"]);

					if(oDbDataReader["SupplierName"] != DBNull.Value)
						oSupplier.SupplierName = Convert.ToString(oDbDataReader["SupplierName"]);

					if(oDbDataReader["Address"] != DBNull.Value)
						oSupplier.Address = Convert.ToString(oDbDataReader["Address"]);

					if(oDbDataReader["Email"] != DBNull.Value)
						oSupplier.Email = Convert.ToString(oDbDataReader["Email"]);

					if(oDbDataReader["Phone"] != DBNull.Value)
						oSupplier.Phone = Convert.ToString(oDbDataReader["Phone"]);

					if(oDbDataReader["Fax"] != DBNull.Value)
						oSupplier.Fax = Convert.ToString(oDbDataReader["Fax"]);

					if(oDbDataReader["PaymentType"] != DBNull.Value)
						oSupplier.PaymentType = Convert.ToInt32(oDbDataReader["PaymentType"]);

					if(oDbDataReader["PaymentDate"] != DBNull.Value)
						oSupplier.PaymentDate = Convert.ToDateTime(oDbDataReader["PaymentDate"]);

					if(oDbDataReader["ATM"] != DBNull.Value)
						oSupplier.ATM = Convert.ToString(oDbDataReader["ATM"]);

					if(oDbDataReader["AccountId"] != DBNull.Value)
						oSupplier.AccountId = Convert.ToInt32(oDbDataReader["AccountId"]);

					if(oDbDataReader["Note"] != DBNull.Value)
						oSupplier.Note = Convert.ToString(oDbDataReader["Note"]);
				}
				oDbDataReader.Close();
				return oSupplier;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddSupplier(string ID,DateTime?CreateDate,DateTime?ModifiedDate,DateTime?TimeStamp,string SupplierCode,string SupplierName,string Address,string Email,string Phone,string Fax,int?PaymentType,DateTime?PaymentDate,string ATM,int?AccountId,string Note)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERT INTO [Supplier]([CreateDate],[ModifiedDate],[TimeStamp],[SupplierCode],[SupplierName],[Address],[Email],[Phone],[Fax],[PaymentType],[PaymentDate],[ATM],[AccountId],[Note])VALUES(@CreateDate,@ModifiedDate,@TimeStamp,@SupplierCode,@SupplierName,@Address,@Email,@Phone,@Fax,@PaymentType,@PaymentDate,@ATM,@AccountId,@Note)",CommandType.Text);
				if (CreateDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,CreateDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,DBNull.Value));
				if (ModifiedDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,ModifiedDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,DBNull.Value));
				if (TimeStamp.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,TimeStamp));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,DBNull.Value));
				if (SupplierCode!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SupplierCode",DbType.String,SupplierCode));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SupplierCode",DbType.String,DBNull.Value));
				if (SupplierName!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SupplierName",DbType.String,SupplierName));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SupplierName",DbType.String,DBNull.Value));
				if (Address!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address",DbType.String,Address));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address",DbType.String,DBNull.Value));
				if (Email!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email",DbType.String,Email));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email",DbType.String,DBNull.Value));
				if (Phone!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Phone",DbType.String,Phone));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Phone",DbType.String,DBNull.Value));
				if (Fax!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax",DbType.String,Fax));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax",DbType.String,DBNull.Value));
				if (PaymentType.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@PaymentType",DbType.Int32,PaymentType));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@PaymentType",DbType.Int32,DBNull.Value));
				if (PaymentDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@PaymentDate",DbType.DateTime,PaymentDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@PaymentDate",DbType.DateTime,DBNull.Value));
				if (ATM!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ATM",DbType.String,ATM));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ATM",DbType.String,DBNull.Value));
				if (AccountId.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,AccountId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,DBNull.Value));
				if (Note!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,Note));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,DBNull.Value));

				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddSupplier(Supplier oSupplier)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERT INTO [Supplier]([CreateDate],[ModifiedDate],[TimeStamp],[SupplierCode],[SupplierName],[Address],[Email],[Phone],[Fax],[PaymentType],[PaymentDate],[ATM],[AccountId],[Note])VALUES(@CreateDate,@ModifiedDate,@TimeStamp,@SupplierCode,@SupplierName,@Address,@Email,@Phone,@Fax,@PaymentType,@PaymentDate,@ATM,@AccountId,@Note)",CommandType.Text);
				if (oSupplier.CreateDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,oSupplier.CreateDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,DBNull.Value));
				if (oSupplier.ModifiedDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,oSupplier.ModifiedDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,DBNull.Value));
				if (oSupplier.TimeStamp.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,oSupplier.TimeStamp));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,DBNull.Value));
				if (oSupplier.SupplierCode!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SupplierCode",DbType.String,oSupplier.SupplierCode));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SupplierCode",DbType.String,DBNull.Value));
				if (oSupplier.SupplierName!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SupplierName",DbType.String,oSupplier.SupplierName));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SupplierName",DbType.String,DBNull.Value));
				if (oSupplier.Address!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address",DbType.String,oSupplier.Address));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address",DbType.String,DBNull.Value));
				if (oSupplier.Email!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email",DbType.String,oSupplier.Email));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email",DbType.String,DBNull.Value));
				if (oSupplier.Phone!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Phone",DbType.String,oSupplier.Phone));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Phone",DbType.String,DBNull.Value));
				if (oSupplier.Fax!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax",DbType.String,oSupplier.Fax));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax",DbType.String,DBNull.Value));
				if (oSupplier.PaymentType.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@PaymentType",DbType.Int32,oSupplier.PaymentType));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@PaymentType",DbType.Int32,DBNull.Value));
				if (oSupplier.PaymentDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@PaymentDate",DbType.DateTime,oSupplier.PaymentDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@PaymentDate",DbType.DateTime,DBNull.Value));
				if (oSupplier.ATM!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ATM",DbType.String,oSupplier.ATM));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ATM",DbType.String,DBNull.Value));
				if (oSupplier.AccountId.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,oSupplier.AccountId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,DBNull.Value));
				if (oSupplier.Note!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,oSupplier.Note));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,DBNull.Value));

				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateSupplier(string ID,DateTime?CreateDate,DateTime?ModifiedDate,DateTime?TimeStamp,string SupplierCode,string SupplierName,string Address,string Email,string Phone,string Fax,int?PaymentType,DateTime?PaymentDate,string ATM,int?AccountId,string Note)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATE [Supplier] SET [CreateDate]=@CreateDate,[ModifiedDate]=@ModifiedDate,[TimeStamp]=@TimeStamp,[SupplierCode]=@SupplierCode,[SupplierName]=@SupplierName,[Address]=@Address,[Email]=@Email,[Phone]=@Phone,[Fax]=@Fax,[PaymentType]=@PaymentType,[PaymentDate]=@PaymentDate,[ATM]=@ATM,[AccountId]=@AccountId,[Note]=@Note WHERE [ID]=@ID",CommandType.Text);
				if (CreateDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,CreateDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,DBNull.Value));
				if (ModifiedDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,ModifiedDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,DBNull.Value));
				if (TimeStamp.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,TimeStamp));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,DBNull.Value));
				if (SupplierCode!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SupplierCode",DbType.String,SupplierCode));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SupplierCode",DbType.String,DBNull.Value));
				if (SupplierName!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SupplierName",DbType.String,SupplierName));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SupplierName",DbType.String,DBNull.Value));
				if (Address!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address",DbType.String,Address));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address",DbType.String,DBNull.Value));
				if (Email!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email",DbType.String,Email));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email",DbType.String,DBNull.Value));
				if (Phone!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Phone",DbType.String,Phone));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Phone",DbType.String,DBNull.Value));
				if (Fax!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax",DbType.String,Fax));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax",DbType.String,DBNull.Value));
				if (PaymentType.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@PaymentType",DbType.Int32,PaymentType));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@PaymentType",DbType.Int32,DBNull.Value));
				if (PaymentDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@PaymentDate",DbType.DateTime,PaymentDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@PaymentDate",DbType.DateTime,DBNull.Value));
				if (ATM!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ATM",DbType.String,ATM));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ATM",DbType.String,DBNull.Value));
				if (AccountId.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,AccountId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,DBNull.Value));
				if (Note!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,Note));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateSupplier(Supplier oSupplier)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATE [Supplier] SET [CreateDate]=@CreateDate,[ModifiedDate]=@ModifiedDate,[TimeStamp]=@TimeStamp,[SupplierCode]=@SupplierCode,[SupplierName]=@SupplierName,[Address]=@Address,[Email]=@Email,[Phone]=@Phone,[Fax]=@Fax,[PaymentType]=@PaymentType,[PaymentDate]=@PaymentDate,[ATM]=@ATM,[AccountId]=@AccountId,[Note]=@Note WHERE [ID]=@ID",CommandType.Text);
				if (oSupplier.CreateDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,oSupplier.CreateDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,DBNull.Value));
				if (oSupplier.ModifiedDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,oSupplier.ModifiedDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,DBNull.Value));
				if (oSupplier.TimeStamp.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,oSupplier.TimeStamp));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,DBNull.Value));
				if (oSupplier.SupplierCode!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SupplierCode",DbType.String,oSupplier.SupplierCode));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SupplierCode",DbType.String,DBNull.Value));
				if (oSupplier.SupplierName!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SupplierName",DbType.String,oSupplier.SupplierName));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SupplierName",DbType.String,DBNull.Value));
				if (oSupplier.Address!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address",DbType.String,oSupplier.Address));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address",DbType.String,DBNull.Value));
				if (oSupplier.Email!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email",DbType.String,oSupplier.Email));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email",DbType.String,DBNull.Value));
				if (oSupplier.Phone!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Phone",DbType.String,oSupplier.Phone));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Phone",DbType.String,DBNull.Value));
				if (oSupplier.Fax!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax",DbType.String,oSupplier.Fax));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax",DbType.String,DBNull.Value));
				if (oSupplier.PaymentType.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@PaymentType",DbType.Int32,oSupplier.PaymentType));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@PaymentType",DbType.Int32,DBNull.Value));
				if (oSupplier.PaymentDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@PaymentDate",DbType.DateTime,oSupplier.PaymentDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@PaymentDate",DbType.DateTime,DBNull.Value));
				if (oSupplier.ATM!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ATM",DbType.String,oSupplier.ATM));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ATM",DbType.String,DBNull.Value));
				if (oSupplier.AccountId.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,oSupplier.AccountId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,DBNull.Value));
				if (oSupplier.Note!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,oSupplier.Note));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,oSupplier.ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveSupplier(Supplier oSupplier)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [Supplier] WHERE [ID]=@ID",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,oSupplier.ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveSupplier(string ID)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [Supplier] WHERE [ID]=@ID",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	}
}
